const express = require('express')
const user = require('../../user')
const router = express.Router()


router.post('/sign',(req,res)=>{
   let userBody = req.body
   user.findAll((err,users)=>{
       if(err){
           throw err
       }
    //    console.log(users);
       console.log(userBody);
       let user = users.find((item)=>{
           return item.uname === userBody.uname
       })
       if(user){
            if(user.upwd === userBody.upwd){
                // 用户名和密码都正确,显示首页
                // res.redirect('/')
                res.send("用户名和密码都正确")
            }else{
                res.send('密码错误')
            }
       }else{
           res.send('用户名不存在')
       }
    //    res.send(users)
   })
   
})

router.get('/classes',(req,res)=>{
    let uid = req.query.uid
    user.findClassByUserId(uid,(err,classes)=>{
        if(err){
            throw err
        }
        if(classes){
            res.send(classes)
        }else{
            res.send("没有对应的班级")
        }
    })
})


module.exports = router